from nnstrategy import *
from nnpcastrategy import *
from webservice_defs import *
import StringIO

class User:

	def __init__(self, userid, gender, interestedin, nn=None, nn_pca=None, 
				 method=NN_ID, default_image=True, image=None, 
				 nn_compressed=None):
		if nn == None:
			nn = NNStrategy()
			
		if nn_pca == None:
			nn_pca = NNPCAStrategy()
			
		self._methods = {NN_ID:nn, NN_PCA_ID:nn_pca}	
		self._id = userid
		self._gender = gender
		self._interestedin = interestedin
		self._method = method
		self._default_image = default_image
		self._image = image
		self._nn_compressed_image = nn_compressed
			
	def set_gender(self, gender):
		self._gender = gender
		
	def set_interestedin(self, interestedin):
		self._interestedin = interestedin
		
	def set_method(self, methodid):
		self._method = methodid
		
	def set_default_image(self, default_image):
		self._default_image = default_image
		
	def set_image(self, image):
		self._image = image
		self._default_image = False
		
	def set_nn_compressed_image(self, nn_compressed_image):
		self._nn_compressed_image = nn_compressed_image
		
	def get_id(self):
		return self._id
		
	def get_gender(self):
		return self._gender
		
	def get_interestedin(self):
		return self._interestedin
		
	def get_method(self):
		return self._method
		
	def get_default_image(self):
		return self._default_image
		
	def get_image(self):
		return self._image
		
	def get_nn_compressed_image(self):
		return self._nn_compressed_image
		
	def get_nn_strategy(self):
		return self._methods[NN_ID]
		
	def get_nn_pca_strategy(self):
		return self._methods[NN_PCA_ID]
	
	def nn_compress_image(self, image):
		return self._methods[NN_ID].compress_image(image)
		
	def is_target_suitable(self, target):
		result = float(MIN_RESPONSE), False
		if self._interestedin == BI_ID or \
		   self._interestedin == target.get_gender():
			result = self._methods[self._method].is_target_suitable(target)
		return result
		
	def train(self, image, compressed_image, response):
		i = image if self._method == NN_PCA_ID else compressed_image
		self._methods[self._method].train(i, response)

